{template header}

<style>
    .gift-show-content{}
    .gift-show-content img{max-width: 100%;}
</style>

<div class="container">
<div class="row">
<div class="col-md-8">
    <div class="panel panel-default">
        <div class="panel-body">
            <div class="page-header">
                <h1>{$strGift[title]}</h1>
            </div>
            <div class="row">
                <div class="col-md-6"><img style="width:100%;" title="点击看大图" src="{if $strGift[photo]}{php echo tsXimg($strGift[photo],'gift',500,'',$strGift[path])}{else}{SITE_URL}app/gift/skins/default/gift.jpg{/if}" /></div>
                <div class="col-md-6">
                    <div class="c9 f12" style="line-height: 25px">
                        发布者： <a href="{tsUrl('user','duty',array('id'=>$strGift[user][userid]))}">{$strGift[user][username]}</a> <br/>
                        属性： {if $strGift[cate]==0}志愿者福利{else}义卖物品{/if}<br/>
                        有效期： {php echo date('Y-m-d H:i',$strGift[limittime])}<br/>
                        {if $strGift[cate]==0}所需积分{else}单价{/if}：{$strGift['price']}<br/>
                        发货地：{$strGift[province]}{$strGift[city]} {$strGift[address]}<br/>
                        交货方式： {if $strGift[transe]==0}不限{/if}{if $strGift[transe]==1}自取{/if}{if $strGift[transe]==2}快递到付{/if}<br/>
                        类型： <a href="{tsUrl('gift','type',array('id'=>$strGift['type']['typeid']))}">{$strGift[type][typename]}</a><br/>
                        数量：{if $strGift['quota']==0}不限{else}{$strGift['quota']}{/if}<br/>
                        {if $strGift[cate]==0}申领{else}下单{/if}数：{$strGift[count_userwish]}<br>
                        完成数：{$strGift[count_userdo]}<br>
                    </div>
                    <div class="tar">
                        {if $TS_USER[userid]&&$strGift[userid]!=$TS_USER[userid]}
                        <a class="pull-right" style="margin-left: 5px" href="javascript:void('0');" onclick="recommend({$strGift[giftid]})">{if $isRecommend==0}<i class="fa fa-heart-o"></i> 赞{else}<i class="fa fa-heart"></i> 取消{/if}</a>
                        {/if}
                        {if $strGift[limittime]<=time()}
                        <img style="float: right;width: 80px;height:auto" src="{SITE_URL}public/images/gift/{$strGift[status]}.png">
                        {else}
                            {if $strGiftUser}
                                {if $strGiftUser[status]==0}
                                     <a class="btn btn-default" href="javascript:void('0');" onclick="cancelGift('{$strGift[giftid]}');"> 我不要了</a>&nbsp;&nbsp;
                                     <a href="{$payurl}" class="btn btn-success" > 支付</a>
                                {/if}
                                {if $strGiftUser[status]==1}
                                    待收货
                                {/if}
                                {if $strGiftUser[status]==2}
                                <a class="btn btn-default" href="javascript:void('0');" onclick="receiveGift('{$strGift[giftid]}');"> 已收货</a>
                                {/if}
                                {if $strGiftUser[status]==3}
                                <a class="btn btn-default" href="javascript:void('0');" onclick="noreceiveGift('{$strGift[giftid]}');"> 撤销收货</a>
                                {/if}
                            {else}
                                     {if $strGift['status']==0}
                                            {if $strGift['count_userwish']<$strGift['quota'] }
                                         <a class="btn btn-success"  data-toggle="modal" data-target="#do_gift_form" >我想要</a>
                                            {else}
                        <a class="btn btn-success"  data-toggle="modal" data-target="#meile" >我想要</a>
                                            {/if}
                                        {else}
                        <img style="float: right;width: 80px;height:auto" src="{SITE_URL}public/images/gift/{$strGift[status]}.png">
                                    {/if}
                            {/if}
                        {/if}
                    </div>
                </div>
            </div>
    </div>
</div>

    <div class="panel panel-default">
        <div class="panel-heading">简介</div>
        <div class="panel-body">
            <div class="gift-content">
                <div class="gift-view">

                    <p>{$strGift[content]}</p>
                </div>
            </div>
<div style="text-align:right;">
{if $GLOBALS[TS_USER][userid] == $strGift[userid] || $GLOBALS[TS_USER][isadmin]=='1'}
<a href="{tsUrl('gift','edit',array('ts'=>'base','giftid'=>$strGift['giftid']))}">修改</a>
&nbsp;&nbsp;<a href="{SITE_URL}index.php?app=gift&ac=delete&ts=base&giftid={$strGift[giftid]}&token={$_SESSION['token']}"  onClick="return confirm('确定删除吗?')">删除</a>
{if $strGift['status']!=0&&$strGift['quota']>$strGift['count_wish'] }<a <a href="javascript:void('0');" onclick="upsell({$strGift[giftid]})">上架</a>{/if}
    {if $strGift['status']==0&&$strGift['count_do']==0}<a <a href="javascript:void('0');" onclick="downsell({$strGift[giftid]})">下架</a>{/if}
{/if}
</div>
</div>
</div>
    <div class="panel panel-default">
        <div class="panel-heading">{if $GLOBALS[TS_USER][userid] == $strGift[userid] || $GLOBALS[TS_USER][isadmin]=='1'}<a href="{tsUrl('gift','edit',array('ts'=>'join','giftid'=>$giftid))}">{/if}下单的人{if $GLOBALS[TS_USER][userid] == $strGift[userid] || $GLOBALS[TS_USER][isadmin]=='1'}</a>{/if} <small>(合计下单{$strGift[count_userwish]}件，点击名字标记发货，名字为橙色表示已下单，{if $strGift[cate]==1}黑色表示已付款，{/if}蓝色表示已发货，绿色表示已经收货)</small></div>
        <div class="panel-body">
            <div class="facelist">
                <ul>
                {loop $arrDoUser $key $item}
                <li>
                    <a href="{tsUrl('user','duty',array('id'=>$item[userid]))}">
                        <img class="img-circle" src="{$item['user'][face]}" alt="{$item['user']['username']}"  width="48" height="48" />
                    </a>
                    <div >
                        {if $item['status']==-1}
                        <a  style="color:gray;text-decoration:line-through; ">{$item['user']['username']}<br/>(退款{$item['quota']})</a>
                        {/if}
                        {if $item['status']==0}
                        <a  style="color:orange">{$item['user']['username']}<br/>(下单{$item['quota']})</a>
                        {/if}
                        {if $item['status']==1}
                        <a {if $GLOBALS[TS_USER][userid] == $strGift[userid]}href="javascript:void('0');" onclick="sendGift({$strGift[giftid]},{$item['userid']})"{/if} style="color:black">{$item['user']['username']}<br/>(付款{$item['quota']})</a>
                        {/if}
                        {if $item['status']==2}
                        <a {if $GLOBALS[TS_USER][userid] == $strGift[userid]}href="javascript:void('0');" onclick="nosendGift({$strGift[giftid]},{$item['userid']})"{/if} style="color:blue">{$item['user']['username']}<br/>(发货{$item['quota']})</a>
                        {/if}
                        {if $item['status']==3}
                        <a  style="color: green">{$item['user']['username']}<br/>(收货{$item['quota']})</a>
                        {/if}
                    </div>
                </li>
                {/loop}
                </ul>
            </div>
    </div>
</div>
    <div class="panel panel-default">
        <div class="panel-heading">你的回应</div>
        <div class="panel-body">
            <div class="comment">
<ul>
{loop $arrComment $key $item}
<li class="clearfix">
    <div class="user-face">
        <a href="{tsUrl('user','duty',array('id'=>$item[user][userid]))}"><img title="{$item[user][username]}" alt="{$item[user][username]}" src="{$item[user][face]}" class="pil img-circle" width="48" height="48" /></a>
    </div>
    <div class="reply-doc">
            <h4>{php echo date('Y-m-d H:i:s',$item[addtime])}
                <a href="{tsUrl('user','topic',array('id'=>$item[userid]))}">{$item[user][username]}</a>
            </h4>
        <p>{$item[content]}</p>

	   {if $GLOBALS[TS_USER][userid] == $strGift[userid]|| $GLOBALS[TS_USER][isadmin]=='1'}
        <div class="group_banned">
            <span>
                <a class="j a_confirm_link" onclick="return confirm('确定删除?')" href="{SITE_URL}index.php?app=gift&ac=delete&ts=comment&giftid={$strGift['giftid']}&commentid={$item['commentid']}">删除</a>
            </span>
        </div>
	{/if}
	    </div>
</li>
{/loop}
</ul>
            </div>
<div class="page">{$pageUrl}</div>
{if $GLOBALS[TS_USER][userid] == ''}
<div style="font-size:14px;padding:40px 0;text-align:center;">请登录后回复 ^_^</div>
{else}
<div>
<form method="POST" action="{tsUrl('gift','comment')}" id="formMini">
    <div class="wangeditor_toolbar" id="tseditor"></div>
    <div class="wangeditor_text" id="tseditor2"></div>
    <div style="display: none"><textarea id="content" name="content"></textarea></div>
<input type="hidden" name="giftid" value="{$strGift[giftid]}" />
<input class="btn btn-success" type="submit" value="发表回复">
</form>
</div>
{/if}
</div>
</div>
</div>
<div class="col-md-4">
    <div class="panel panel-default">
        <div class="panel-body">
<a href="{tsUrl('gift','type',array(id=>$strGift[type][typeid]))}">更多{$strGift[type][typename]}商品</a>
</div>
</div>


    <!--广告位-->
    {php doAction('gobad','300')}
</div>
</div>
</div>
<div id="do_gift_form" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h5 class="modal-title">下单</h5>
            </div>
            <div class="modal-body" >
                {if $strGift[cate]!=0}
                <div class="form-group">
                    <div class="col-sm-12">
                        <div class="content">{$strTopic['content']}</div>
                    </div>
                </div>
                {/if}
                <form  id="join_form" class="form-horizontal" method="post" action="{SITE_URL}index.php?app=gift&ac=do&ts=join">

                    <div class="form-group">
                        <label class="col-sm-2 control-label">姓名</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="username" name="username">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">手机</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="phone" name="phone" value="{$GLOBALS[TS_USER][phone]}">
                        </div>
                    </div>
                    {if $strGift[cate]==1}
                    <div class="form-group">
                        <label class="col-sm-2 control-label">数量</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="quota" name="quota" value="{$remain}">
                        </div>
                    </div>
                    {if $strGift[transfer]==2}
 <!--                   {if $strGift[transfer]==0}
                    <div class="form-group">
                        <label class="col-sm-2 control-label">交货方式</label>
                        <div class="col-sm-10">
                            <select name="transfer" id="transfer"  class="form-control">
                                <option></option>
                                <option value="1">自取</option>
                                <option value="2">包邮</option>
                            </select>
                        </div>
                    </div>
                    {/if}-->
                    <div class="form-group">
                        <label class="col-sm-2 control-label">收货地址</label>
                        <div class="col-sm-10" id="city_3">
                            <p><select id="province" name="province" class="prov form-control"></select></p>
                            <p><select id="city" name="city" class="city form-control" disabled="disabled"></select></p>
                            <p><input type="text" id="address" name="address" value="" class="form-control"></p>
                        </div>
                    </div>
                    {/if}
                    {/if}
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">

                            <input type="hidden" id="giftid" name="giftid" value="{$strGift['giftid']}" />

                            <button type="submit" class="btn btn-success">点击提交</button>
                        </div>
                    </div>
                </form>

            </div>
        </div>
    </div>
</div>

<div id="meile" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h5 class="modal-title">友情提示</h5>
            </div>
            <div class="modal-body" >

                <div class="form-group">
                    <div class="col-sm-12">
                        <div class="content">别人手快，已经下单！如果他没有及时支付，您仍然有机会。再等等看哈。</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{if $GLOBALS[TS_USER][userid] == $strGift[userid]&&$count_pay>0}

<div id="sent_alert" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"  style="overflow:scroll;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h5 class="modal-title">发货提醒</h5>
            </div>
            <div class="modal-body" >
                <div class="form-group">
                    <i class="fa fa-arrow-down" aria-hidden="true"></i> 有买家已付款，请查看左下方名单，名字黑色表示已付款。
                </div>
                <div class="form-group">
                    点击“下单的人”可获取收货地址等信息，请尽快发货。
                </div>
                <div class="form-group">
                    发货后，点击下单区名字（不是头像）确认发货。确认后名字会变成蓝色。
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $('#sent_alert').modal('show');
</script>

{/if}
<script>
    $(function(){
        $('#formMini').on('submit', function(e) {
            var content  = $('#content').val();
            var text = Trim(content,'g');
            if(text == ''){
                bootbox.alert('内容不能为空');
                return false;
            }
        });
    });

    $(function(e){
        $('#join_form').on('submit', function(e) {
            var giftid  = $('#giftid').val();
            var username  = $('#username').val();
            var phone = $('#phone').val();
            if(username==''){
                bootbox.alert('姓名必填');
                return false;
            }

            if(phone==''){
                bootbox.alert('手机必填');
                return false;
            }

            {if $strGift['cate']==1}

                if(quota==''){
                    bootbox.alert('数量必填');
                    return false;
                }

                {if $strGift['transfer']==0 }
                    if(transfer==''){
                        bootbox.alert('交货方式必填');
                        return false;
                    }

                {/if}

                    if(transfer==2&&(province==''||city==''||address=='')){
                        bootbox.alert('请填写完整的收货地址');
                        return false;
                    }

                    {if $strGift['transfer']==2 }
                        if(province==''||city==''||address==''){
                            bootbox.alert('请填写完整的收货地址');
                            return false;
                        }

                    {/if}

            {/if}

        });

    });


    //确认收货
    function receiveGift(giftid,userid){
        if (confirm('确定已收货吗？')) {
            $.ajax({
                type: "POST",
                url: siteUrl+"index.php?app=gift&ac=do&ts=receive",
                data: "giftid="+giftid+"&memberid="+userid,
                beforeSend:function(){
                },
                success:function(result){
                        window.location.reload();
                }
            });

        }
    }

    //取消收货
    function noreceiveGift(giftid,userid){
        if (confirm('确定没收货吗？')) {
            $.ajax({
                type: "POST",
                url: siteUrl+"index.php?app=gift&ac=do&ts=noreceive",
                data: "giftid="+giftid+"&memberid="+userid,
                beforeSend:function(){
                },
                success:function(result){
                        window.location.reload();
                }
            });

        }
    }

    //确认发货
    function sendGift(giftid,userid){
        if (confirm('确定已发货吗？')) {
            $.ajax({
                type: "POST",
                url: siteUrl+"index.php?app=gift&ac=do&ts=send",
                data: "giftid="+giftid+"&memberid="+userid,
                beforeSend:function(){
                },
                success:function(result){
                        window.location.reload();
                }
            });

        }
    }

    //取消发货
    function nosendGift(giftid,userid){
        if (confirm('确定没发货吗？')) {
            $.ajax({
                type: "POST",
                url: siteUrl+"index.php?app=gift&ac=do&ts=nosend",
                data: "giftid="+giftid+"&memberid="+userid,
                beforeSend:function(){
                },
                success:function(result){
                        window.location.reload();
                }
            });

        }
    }

    //上架
    function upsell(giftid){
        if (confirm('确定上架吗？')) {
            $.ajax({
                type: "POST",
                url: siteUrl+"index.php?app=gift&ac=do&ts=upsell",
                data: "giftid="+giftid,
                beforeSend:function(){
                },
                success:function(result){
                        window.location.reload();
                }
            });

        }
    }

    //下架
    function downsell(giftid){
        if (confirm('确定下架吗？')) {
            $.ajax({
                type: "POST",
                url: siteUrl+"index.php?app=gift&ac=do&ts=downsell",
                data: "giftid="+giftid,
                beforeSend:function(){
                },
                success:function(result){
                        window.location.reload();
                }
            });

        }
    }
</script>

{if $strGiftUser}

{if $strGiftUser[status]==0}

<div id="pay_form" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h5 class="modal-title">请点击按钮支付</h5>
            </div>
            <div class="modal-body" >
                <a href="{$payurl}" class="btn btn-success btn-block" > 支付</a>
            </div>
        </div>
    </div>
</div>

<script>
    $('#pay_form').modal('show');
</script>

{/if}

{if $strGiftUser[status]==2}
<div id="do_receive_form" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h5 class="modal-title">收货</h5>
            </div>
            <div class="modal-body" >
                <button name="types" type="submit" class="btn btn-success btn-block" onclick="receiveGift({$giftid},{$TS_USER['userid']})">我已收货</button>
            </div>
        </div>
    </div>
</div>

<script>
    $('#do_receive_form').modal('show');
</script>

{/if}

{/if}
{php doAction('tseditor','mini')}
{template footer}